<?php

namespace App\Http\Controllers\Wechat\Messages;

use Laravel\Lumen\Routing\Controller as BaseController;
use EasyWeChat\Foundation\Application;

/**
 * 通知
 * Class Notices
 * @package App\Http\Controllers\Wechat\Messages
 */
class Notices extends BaseController
{
    /**
     * 大学英语四六级通知
     * @param $openid
     * @param $data
     * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
     */
    public static function cet( $openid, $name, $school, $number, $detail, $remark, $url = '' )
    {
        $templateId = 'jK_1ydRcPb1D6qQ9yfsZnjdJq_eLvMB71aO30YzD0M8';

        $data = [
            'first'    => '',
            'keyword1' => $name,
            'keyword2' => $school,
            'keyword3' => $number,
            'keyword4' => $detail,
            'remark'   => $remark
        ];

        return (new Application( config( 'wechat' ) ))->notice->withTo( $openid )->withUrl( $url )->withTemplate( $templateId )->withData( $data )->send();
    }

    /**
     * 期末考试成绩
     * @param $openid
     * @param $name
     * @param $score
     * @param $remark
     * @param string $url
     * @return mixed
     */
    public static function scoreFinal( $openid, $first, $name, $scores, $remark = '', $url = '' )
    {
        $templateId = 'UWkURHehfMuN0-h4Q2CK-cI9B2ex4S0Qs6lDVLOPkvA';

        $data = [
            'first'      => [$first, '#000'],
            'childName'  => $name,
            'courseName' => '期末考试',
            'score'      => $scores,
            'remark'     => $remark
        ];

        return (new Application( config( 'wechat' ) ))->notice->withTo( $openid )->withUrl( $url )->withTemplate( $templateId )->withData( $data )->send();
    }


    /**
     * 快递新消息提醒
     * @param $openid
     * @param $first
     * @param $num
     * @param $context
     * @param $time
     * @param string $remark
     * @param string $url
     * @return mixed
     */
    public static function expressTracking( $openid, $first, $num, $context, $time, $remark = '', $url = '' )
    {
        $templateId = 'l3SsVLLPPvVE4Zs26rzbuMj6ixFX3n9wzRAgPVCHGI0';

        $data = [
            'first'    => $first,
            'keyword1' => $num,
            'keyword2' => $context,
            'keyword3' => $time,
            'remark'   => [$remark, '#000']
        ];

        return (new Application( config( 'wechat' ) ))->notice->withTo( $openid )->withUrl( $url )->withTemplate( $templateId )->withData( $data )->send();
    }

}
